package com.bitbank.smartdevice.ui.shop

import android.support.v7.widget.GridLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuInflater
import android.view.View
import com.bitbank.smartdevice.R
import com.bitbank.smartdevice.adapter.base.CommonAdapter
import com.bitbank.smartdevice.adapter.base.MViewHolder
import com.bitbank.smartdevice.adapter.base.SpacesItemDecoration
import com.bitbank.smartdevice.ui.base.BaseListFragment
import com.bitbank.smartdevice.vo.Product
import com.qmuiteam.qmui.util.QMUIDisplayHelper
import kotlinx.android.synthetic.main.fragment_shop.view.*

/**
 *  Date：2018/12/10
 *  Author：xulee
 *  Desc：商城
 */

class ShopFragment : BaseListFragment<Product>() {
    override fun getLayoutID(): Int = R.layout.fragment_shop

    override fun initView(v: View) {
        super.initView(v)
        v.topBar.setTitle(R.string.title_mall)
    }

    override fun getRecycleView(v: View): RecyclerView {
        v.recycleView.layoutManager = GridLayoutManager(context, 2)
        v.recycleView.addItemDecoration(
            SpacesItemDecoration(
                QMUIDisplayHelper.dpToPx(10),
                QMUIDisplayHelper.dpToPx(16)
            )
        )
        return v.recycleView
    }

    override fun getInnerAdapter(): CommonAdapter<Product> {
        val example0 = Product(
            "智能排座USL1.0.1 升级内测1",
            120.3,
            "https://img14.360buyimg.com/n1/s450x450_jfs/t1/1533/6/5237/158730/5b9f3eceE29188f86/f408c95922f1a145.jpg"
        )
        val example1 = Product(
            "智能排座USL1.0.1 升级内测2",
            322.3,
            "https://img14.360buyimg.com/n4/jfs/t23545/103/2622406620/58635/5b687/5b889f1aNb490c6fb.jpg"
        )
        val mDatas = arrayOf(example0, example1)
        return object : CommonAdapter<Product>(context!!, R.layout.list_item_mall, mDatas) {
            override fun convert(holder: MViewHolder, t: Product, position: Int) {
                holder.setText(R.id.tvName, t.name)
                    .setText(R.id.tvPrice, "￥ " + t.price)
                    .setImageUrl(R.id.ivThumbnail, t.thumbnail)
            }
        }
    }

    override fun getHeaderView(): View? {
        return LayoutInflater.from(context).inflate(R.layout.layout_header_shop, null, false)
    }

    override fun loadData() {

    }

    override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) {
        menu?.clear()
        super.onCreateOptionsMenu(menu, inflater)
    }
}